home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / setfunction.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  114 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: setfunction.c,v 1.7 1996/10/24 15:36:47 aros Exp $
  4.     $Log: setfunction.c,v $
  5.     Revision 1.7  1996/10/24 15:36:47  aros
  6.     Named all macros which the user/developer can use as "AROS".
  7.  
  8.     For some strange reason, GCC produces incorrect code for "x /= -5;". "x = (-x)
  9.     / 5" works...
  10.  
  11.     Revision 1.6  1996/10/23 14:28:54  aros
  12.     Use the respective macros to access and manipulate a libraries' jumptable
  13.  
  14.     Revision 1.5  1996/10/19 17:07:27  aros
  15.     Include <aros/machine.h> instead of machine.h
  16.  
  17.     Revision 1.4  1996/08/13 13:56:08  digulla
  18.     Replaced AROS_LA by AROS_LHA
  19.     Replaced some AROS_LH*I by AROS_LH*
  20.     Sorted and added includes
  21.  
  22.     Revision 1.3  1996/08/01 17:41:19  digulla
  23.     Added standard header for all files
  24.  
  25.     Desc:
  26.     Lang: english
  27. */
  28. #include <exec/execbase.h>
  29. #include <aros/libcall.h>
  30. #include <aros/machine.h>
  31.  
  32. /*****************************************************************************
  33.  
  34.     NAME */
  35.     #include <clib/exec_protos.h>
  36.  
  37.     AROS_LH3(APTR, SetFunction,
  38.  
  39. /*  SYNOPSIS */
  40.     AROS_LHA(struct Library *, library,     A1),
  41.     AROS_LHA(LONG,             funcOffset,  A0),
  42.     AROS_LHA(APTR,             newFunction, D0),
  43.  
  44. /*  LOCATION */
  45.     struct ExecBase *, SysBase, 70, Exec)
  46.  
  47. /*  FUNCTION
  48.     Replaces a certain jumptable entry with another one. This function only
  49.     Forbid()s taskswitching but doesn't Disable() interrupts. You have
  50.     to do your own arbitration for functions which are callable from
  51.     interrupts.
  52.  
  53.     INPUTS
  54.     library     - Pointer to library structure.
  55.     funcOffset  - Offset of the jumpvector from the library base address in
  56.               bytes.
  57.     newFunction - New jumptable entry (pointer to the new function).
  58.  
  59.     RESULT
  60.     Old jumptable entry (pointer to the old function).
  61.  
  62.     NOTES
  63.     While it's more or less safe to patch a library vector with
  64.     SetFunction() it's not possible to safely remove the patch later.
  65.     So don't use this function if it can be avoided.
  66.  
  67.     EXAMPLE
  68.  
  69.     BUGS
  70.  
  71.     SEE ALSO
  72.     MakeLibrary(), MakeFunctions(), SumLibrary().
  73.  
  74.     INTERNALS
  75.  
  76.     HISTORY
  77.  
  78. ******************************************************************************/
  79. {
  80.     AROS_LIBFUNC_INIT
  81.     APTR ret;
  82.  
  83.     funcOffset = (-funcOffset) / LIB_VECTSIZE;
  84.  
  85.     /*
  86.     Arbitrate for the jumptable. This isn't enough for interrupt callable
  87.     functions - but it need not be.
  88.     */
  89.     Forbid();
  90.  
  91.     /* Mark the library as changed. */
  92.     library->lib_Flags|=LIBF_CHANGED;
  93.  
  94.     /* Get old vector. */
  95.     ret = __AROS_GETVECADDR (library, funcOffset);
  96.  
  97.     /* Write new one. */
  98.     __AROS_SETVECADDR (library, funcOffset, newFunction);
  99.  
  100.     /* And clear the instructiuon cache. */
  101.     CacheClearE (__AROS_GETJUMPVEC(library,funcOffset),LIB_VECTSIZE,CACRF_ClearI);
  102.  
  103.     /* Arbitration is no longer needed */
  104.     Permit();
  105.  
  106.     /* Sum the library up again */
  107.     SumLibrary(library);
  108.  
  109.     /* All done. */
  110.     return ret;
  111.     AROS_LIBFUNC_EXIT
  112. } /* SetFunction */
  113.  
  114.